/****************************************************************************
*	Tipovi Dopisa
*	administracija
*
*/
function DopisTypeEdit(btn){
	var tr = btn.parentNode.parentNode;
	var table = tr.parentNode;
	var dtid = tr.getAttribute("dtid");
	var dtname = tr.getAttribute("dtname");
	
	dtid = parseInt(dtid)>0?dtid:0;
	var c = document.getElementById("templateDopis").cloneNode(true);
	c.id = null;
	if(dtid>0){
		tr.parentNode.insertBefore(c,tr);
		table.cancelTr = tr;
		table.removeChild(tr);
		
		var inpts = c.getElementsByTagName("input");
		inpts[0].value = dtid;
		inpts[1].value = dtname;
	}else{
		tr.parentNode.appendChild(c);
	}
}
function DopisTypeCancelEdit(btn){
	var tr = btn.parentNode.parentNode;
	var table = tr.parentNode;
	
	if(table.cancelTr){
		table.insertBefore(table.cancelTr,tr);
	}
	table.removeChild(tr);
	table.cancelTr = null;
}
function DopisTypeSave(btn){
	var tr = btn.parentNode.parentNode;
	var inpts = tr.getElementsByTagName("input");
	var dtid = inpts[0].value;
	var dtname = trim(inpts[1].value);
	if(dtname.length>0){
		var action = "ugovori.php?a=admin&mod=dopistypesave";
		action += "&id="+dtid;
		action += "&name="+escape(dtname);
		LoadRSDoc(action,'afterDopisTypeSave');
	}else{
		alert("Morate uneti naziv!");
	}
}
function afterDopisTypeSave(response){
	var tmp = response.split("{!}");
	var code = parseInt(tmp[0]);
	var msg = tmp[1];
	alert(tmp[1]);
	if(!code){
		LoadRSDoc("ugovori.php?a=admin&mod=dopistype","setContent");
	}
}
function DopisTypeDelete(id){
	LoadRSDoc("ugovori.php?a=admin&mod=dopistypedelete&id="+id,'afterDopisTypeDelete');
}
function afterDopisTypeDelete(response){
	var tmp = response.split("{!}");
	var code = parseInt(tmp[0]);
	var msg = tmp[1];
	alert(msg);
	if(!code){
		LoadRSDoc("ugovori.php?a=admin&mod=dopistype","setContent");
	}
}

/****************************************************************************
*	Ishodi Dopisa
*	administracija
*
*/
function DopisIshodSave(btn){
	var tr = btn.parentNode.parentNode;
	var inpts = tr.getElementsByTagName("input");
	var dtid = inpts[0].value;
	var dtname = trim(inpts[1].value);
	if(dtname.length>0){
		var action = "ugovori.php?a=admin&mod=dopisishodsave";
		action += "&id="+dtid;
		action += "&name="+escape(dtname);
		LoadRSDoc(action,'afterDopisIshodSave');
	}else{
		alert("Morate uneti naziv!");
	}
}
function afterDopisIshodSave(response){
	var tmp = response.split("{!}");
	var code = parseInt(tmp[0]);
	var msg = tmp[1];
	alert(tmp[1]);
	if(!code){
		LoadRSDoc("ugovori.php?a=admin&mod=dopisishod","setContent");
	}
}
function DopisIshodDelete(id){
	LoadRSDoc("ugovori.php?a=admin&mod=dopisishoddelete&id="+id,'afterDopisIshodDelete');
}
function afterDopisIshodDelete(response){
	var tmp = response.split("{!}");
	var code = parseInt(tmp[0]);
	var msg = tmp[1];
	alert(msg);
	if(!code){
		LoadRSDoc("ugovori.php?a=admin&mod=dopisishod","setContent");
	}
}